//
//  SelectController.m
//  NoNameAmazing
//
//  Created by liuyang on 2017/9/19.
//  Copyright © 2017年 北京执行力科技有限公司. All rights reserved.
//

#import "SelectController.h"
#import "SelectCell.h"
#import "SelectModel.h"
@interface SelectController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSArray * array;
@property(nonatomic,strong)SelectModel * selectModel;


@end

@implementation SelectController
{
   NSInteger _selectRow;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if ([self.selectStr isEqualToString:@"NGXM"]) {
       [self requestGuan];
    }else if ([self.selectStr isEqualToString:@"MZM"]){
       [self requestmz];
    }else if ([self.selectStr isEqualToString:@"GJDQM"]){
        [self requestgj];
    }else if ([self.selectStr isEqualToString:@"JKZKMC"]){
        [self requestjk];
    }else if ([self.selectStr isEqualToString:@"ZYJSZWM"]){
        [self requestzw];
    }else if ([self.selectStr isEqualToString:@"RXQHKLBMC"]){
        [self requesthk];
    }else if ([self.selectStr isEqualToString:@"SFDB"]){
        self.array = @[@"是",@"否"];
    }
    
    [self createTable];
    _selectRow=10000;
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonTitle:@"完成" image:nil frame:CGRectMake(0, 0, 30, 20) target:self sel:@selector(sureClick)];
}

-(void)requestGuan
{
    [NetWorkManager requestWithType:0 withUrlString:@"/selectInformation/getHomerelation.do" withParaments:nil withSuccessBlock:^(id object) {
        if ([object[@"message"]isEqualToString:@"获取信息成功"]) {
            _array =[SelectModel mj_objectArrayWithKeyValuesArray: object[@"rslist"]];
            [_tableView reloadData];
        }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];
}

-(void)requestmz
{
    [NetWorkManager requestWithType:0 withUrlString:@"/selectInformation/getnation.do" withParaments:nil withSuccessBlock:^(id object) {
        if ([object[@"message"]isEqualToString:@"获取信息成功"]) {
            _array =[SelectModel mj_objectArrayWithKeyValuesArray: object[@"rslist"]];
            [_tableView reloadData];
        }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];
}

-(void)requestgj
{
    [NetWorkManager requestWithType:0 withUrlString:@"/selectInformation/getcountry.do" withParaments:nil withSuccessBlock:^(id object) {
        if ([object[@"message"]isEqualToString:@"获取信息成功"]) {
            _array =[SelectModel mj_objectArrayWithKeyValuesArray: object[@"rslist"]];
            [_tableView reloadData];
        }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];

}

-(void)requestzw
{
    [NetWorkManager requestWithType:0 withUrlString:@"/selectInformation/getcareer.do" withParaments:nil withSuccessBlock:^(id object) {
        if ([object[@"message"]isEqualToString:@"获取信息成功"]) {
            _array =[SelectModel mj_objectArrayWithKeyValuesArray: object[@"rslist"]];
            [_tableView reloadData];
        }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];

}
-(void)requestjk
{
    [NetWorkManager requestWithType:0 withUrlString:@"/selectInformation/gethealth.do" withParaments:nil withSuccessBlock:^(id object) {
        if ([object[@"message"]isEqualToString:@"获取信息成功"]) {
            _array =[SelectModel mj_objectArrayWithKeyValuesArray: object[@"rslist"]];
            [_tableView reloadData];
        }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];

}

-(void)requesthk
{
    [NetWorkManager requestWithType:0 withUrlString:@"/selectInformation/getHUKOU.do" withParaments:nil withSuccessBlock:^(id object) {
        if ([object[@"message"]isEqualToString:@"获取信息成功"]) {
            _array =[SelectModel mj_objectArrayWithKeyValuesArray: object[@"rslist"]];
            [_tableView reloadData];
        }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];

}

-(void)createTable
{
    
    _tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height-44) style:UITableViewStyleGrouped];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.showsHorizontalScrollIndicator=NO;
    _tableView.userInteractionEnabled= YES ;
    
    _tableView.contentInset = UIEdgeInsetsMake(0, 0, -5, 0);
    
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:_tableView];
}

#pragma mark - 数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    SelectCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"SelectCell" owner:nil options:nil] lastObject];
    if ([self.selectStr isEqualToString:@"SFDB"]){
        self.array = @[@"是",@"否"];
        cell.titleLab.text = _array[indexPath.row];
    }else{

    _selectModel = _array[indexPath.row];
    cell.titleLab.text = _selectModel.NAME;
    }
    if (indexPath.row == _selectRow) {
        cell.selectBtn.hidden = NO;
       
    }
    return cell;
}
#pragma mark - 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 43;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.0001;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     _selectRow = indexPath.row;
    SelectCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selectBtn.hidden = NO;
}

-(void)sureClick
{
    _selectModel = _array[_selectRow];
    if ([self.selectStr isEqualToString:@"NGXM"]) {
        //创建字典
        NSDictionary *dict = @{@"code":_selectModel.CODE,@"name":_selectModel.NAME};
        //发送通知
        [[NSNotificationCenter defaultCenter]postNotificationName:@"volue" object:nil userInfo:dict];
        [self.navigationController popViewControllerAnimated:YES];
    }else if ([self.selectStr isEqualToString:@"MZM"]){
        //创建字典
        NSDictionary *dict = @{@"mzm":_selectModel.CODE,@"mz":_selectModel.NAME};
        //发送通知
        [[NSNotificationCenter defaultCenter]postNotificationName:@"MZM" object:nil userInfo:dict];
        [self.navigationController popViewControllerAnimated:YES];  }
    else if ([self.selectStr isEqualToString:@"GJDQM"]){
            //创建字典
            NSDictionary *dict = @{@"gjm":_selectModel.CODE,@"gj":_selectModel.NAME};
            //发送通知
            [[NSNotificationCenter defaultCenter]postNotificationName:@"GJDQM" object:nil userInfo:dict];
            [self.navigationController popViewControllerAnimated:YES];
    }else if ([self.selectStr isEqualToString:@"JKZKMC"]){
        //创建字典
        NSDictionary *dict = @{@"jkm":_selectModel.CODE,@"jk":_selectModel.NAME};
        //发送通知
        [[NSNotificationCenter defaultCenter]postNotificationName:@"JKZKMC" object:nil userInfo:dict];
        [self.navigationController popViewControllerAnimated:YES];
    }else if ([self.selectStr isEqualToString:@"JKZKMC"]){
        //创建字典
        NSDictionary *dict = @{@"jkm":_selectModel.CODE,@"jk":_selectModel.NAME};
        //发送通知
        [[NSNotificationCenter defaultCenter]postNotificationName:@"JKZKMC" object:nil userInfo:dict];
        [self.navigationController popViewControllerAnimated:YES];
    }else if ([self.selectStr isEqualToString:@"ZYJSZWM"]){
        //创建字典
        NSDictionary *dict = @{@"zwm":_selectModel.CODE,@"zw":_selectModel.NAME};
        //发送通知
        [[NSNotificationCenter defaultCenter]postNotificationName:@"ZYJSZWM" object:nil userInfo:dict];
        [self.navigationController popViewControllerAnimated:YES];
    }else if ([self.selectStr isEqualToString:@"RXQHKLBMC"]){
        //创建字典
        NSDictionary *dict = @{@"hkm":_selectModel.CODE,@"hk":_selectModel.NAME};
        //发送通知
        [[NSNotificationCenter defaultCenter]postNotificationName:@"RXQHKLBMC" object:nil userInfo:dict];
        [self.navigationController popViewControllerAnimated:YES];
    }else if ([self.selectStr isEqualToString:@"SFDB"]){
        NSString * str = _array[_selectRow];
        NSDictionary *dict;
        if ([str isEqualToString:@"是"]) {
            
            dict = @{@"sfdbm":@"1",@"sfdb":@"是"};
        }else {
            
            dict = @{@"sfdbm":@"0",@"sfdb":@"否"};
        }

        //发送通知
        [[NSNotificationCenter defaultCenter]postNotificationName:@"SFDB" object:nil userInfo:dict];
        [self.navigationController popViewControllerAnimated:YES];
    }


   

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
